package org.smart4j.framework.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by Lin on 2018/04/16.
 */
public final class StreamUtil {
    private static final Logger logger = LoggerFactory.getLogger(StreamUtil.class);

    public static String getString(InputStream in){
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuilder sb = new StringBuilder();
        String text = null;
        try {
            while ((text = reader.readLine()) != null){
                sb.append(text);
            }
        } catch (IOException e) {
            logger.error("get String failure", e);
            throw new RuntimeException(e);
        }
        return sb.toString();
    }
}
